
package se.energimyndigheten.lampguiden;

import android.accessibilityservice.AccessibilityServiceInfo;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.provider.Settings;
import android.view.accessibility.AccessibilityManager;
import android.webkit.WebView;
import android.widget.Toast;

import java.util.List;

@TargetApi(14)
public class CompatICS extends Compat {
    @Override
    public boolean isAccessibilityEnabled(Context ctx) {
        AccessibilityManager accessibilityManager =
            (AccessibilityManager) ctx.getSystemService(Context.ACCESSIBILITY_SERVICE);
        List<AccessibilityServiceInfo> spoken = accessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_SPOKEN);

        return (spoken != null && spoken.size()>0);
    }

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    public void enableJavaScript(WebView wv) {
        // Note: Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION is @hide so the string is used here
        final int injectionSetting = Settings.Secure.getInt(
                wv.getContext().getContentResolver(), "accessibility_script_injection", 0);
        if  (injectionSetting == 1)
            wv.getSettings().setJavaScriptEnabled(true);
        else
            Toast.makeText(wv.getContext(), R.string.enable_web_accessibility, Toast.LENGTH_LONG).show();
    }
}
